<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  // 1用于交换变量
  let x = 1;
  let y = 2;

  [x, y] = [y, x];
  console.log(x)

  // 2从函数返回多个值
  function test() {
    return [1, 2, 3]
  }

  let [u, o, p] = test();
  console.log(p)

  function example() {
    return {
      foo: "hello",
      bar: "xixix"
    }
  }
  let { foo: hi, bar: cc } = example();
  console.log(hi)

  // 3函数参数的定义

  // 入参是顺序的
  function f([a, b, c]) {
    console.log(a, b, c)
  };
  f([1, 2, 3]);
  // 入参无序
  function f2({ x, y, z }) {
    console.log(x, y, z)
  };
  f2({ x: 2, z: 44, y: 3 });

  // 4提取json数据
  let jsonStr = {
    id: 42,
    status: "OK",
    data: [333, 121]
  };
  let { id, status, data } = jsonStr;
  console.log(id, status, data)

  // 5函数参数的默认值
  // jQuery.ajax = function (url, {
  //   async = true,
  //   beforeSend = function () { },
  //   cache = true,
  //   complete = function () { },
  //   crossDomain = false,
  //   global = true
  // } = {}){
  //   // todo
  // }

  // 6遍历map结构（只要含有Iterator 迭代器的对象，都可以使用for of迭代）

  const map = new Map();
  map.set("first","hello");
  map.set("second","world");

  for(let [key,value] of map){
    console.log(key+" is "+value);
  }

  // 只获取key
  for(let [key] of map){
    console.log(key)
  }
  // 只获取value
  for(let [,value] of map){
    console.log(value)
  }

  // 7输入模块的指定方法
</script>

</html>